package com.atguigu.tingshu.album.mapper;


import com.atguigu.tingshu.model.album.AlbumStat;
import com.atguigu.tingshu.vo.album.AlbumListStartVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AlbumStatMapper extends BaseMapper<AlbumStat> {


    AlbumListStartVo findAlbumStartValue(Long albumId);

    @Select("select ast.album_id,\n" +
            "    max(if(ast.stat_type = '0401', ast.stat_num, 0)) playStatNum,\n" +
            "    max(if(ast.stat_type = '0402', ast.stat_num, 0)) subscribeStatNum,\n" +
            "    max(if(ast.stat_type = '0403', ast.stat_num, 0)) buyStatNum,\n" +
            "    max(if(ast.stat_type = '0404', ast.stat_num, 0)) commentStatNum\n" +
            "    from album_stat ast\n" +
            "    where ast.album_id=#{albumId}\n" +
            "    group by ast.album_id")
    AlbumStatVo getAlbumStartInfo(Long albumId);
}
